<%--
  Created by IntelliJ IDEA.
  User: acer
  Date: 2024/9/23
  Time: 10:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" %>
<%  String id = request.getParameter("stuid"); %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>条件查询</title>
    <%!
        ResultSet rs;//数据库查询结果集对象
    %>
    <%
        String dbName = "jdbc";//数据库名称
        String userName ="root";//账号
        String dbPassword = "123456";//密码
        String url = "jdbc:mysql://192.168.13.11/"+dbName+"?user="+userName+"&password="+dbPassword;
        Class.forName("com.mysql.jdbc.Driver");//加载数据库驱动
        Connection conn = DriverManager.getConnection(url);//连接数据库
        Statement statement=conn.createStatement();//数据库
        String sql = "select * from student where id ="+id;//查询 student表的sql命令
        rs = statement.executeQuery(sql);//执行查询操作

    %>
</head>
<body>
<table border="1">
    <th colspan="4" style="font-size: x-large; alignment:center";>学生表信息</th>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>所在班级</td>
    </tr>
    <%-- 循环查询结果集    --%>
    <% while (rs.next()){ %>
    <%-- 使用表达式显示结果集中对应的列值        --%>
    <tr style="text-align: center">
        <td><%=rs.getString(1) %></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString("birthday")%></td>
        <td><%= rs.getString("student_name")%></td>
    </tr>
    <% } %>
    <%--   查询结束 关闭结果集，student对象和数据库连接    --%>
    <%
        rs.close();
        statement.close();
        conn.close();
    %>
</table>
</body>
</html>
